package com.dianneng.show.widget;

import android.content.Context;
import android.widget.TextView;

import com.dianneng.show.R;
import com.dianneng.show.model.MonthInfo;
import com.dianneng.show.util.DateUtil;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import java.util.ArrayList;
import java.util.List;

public class XY2MarkerView extends MarkerView {
    private TextView tvContent,tvContent2;
    private Context mContext;

    List<MonthInfo.DataBean> monthDatas1 = new ArrayList<>();
    List<MonthInfo.DataBean> monthBarDatas1 = new ArrayList<>();

    List<MonthInfo.DataBean> monthDatas2 = new ArrayList<>();
    List<MonthInfo.DataBean> monthBarDatas2 = new ArrayList<>();

    private DateUtil.DateInfo dateInfo1, dateInfo2;

    public void setMonthDatas1(List<MonthInfo.DataBean> monthDatas1) {
        this.monthDatas1 = monthDatas1;
    }

    public void setMonthBarDatas1(List<MonthInfo.DataBean> monthBarDatas1) {
        this.monthBarDatas1 = monthBarDatas1;
    }

    public void setMonthDatas2(List<MonthInfo.DataBean> monthDatas2) {
        this.monthDatas2 = monthDatas2;
    }

    public void setMonthBarDatas2(List<MonthInfo.DataBean> monthBarDatas2) {
        this.monthBarDatas2 = monthBarDatas2;
    }

    public void setDateInfo1(DateUtil.DateInfo dateInfo1) {
        this.dateInfo1 = dateInfo1;
    }

    public void setDateInfo2(DateUtil.DateInfo dateInfo2) {
        this.dateInfo2 = dateInfo2;
    }

    public XY2MarkerView(Context context) {
        super(context, R.layout.custom_marker_view2);
        mContext=context;
        tvContent = findViewById(R.id.tvContent);
        tvContent2 = findViewById(R.id.tvContent2);
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        if (dateInfo1==null || monthBarDatas1==null || monthDatas1==null){
            tvContent.setText(e.getY()+"kW·h");
            tvContent2.setText(e.getY()+"kW·h");
        }else {
            tvContent.setText(dateInfo1.getMonth()+"月：当日"+monthBarDatas1.get((int)e.getX()-1).getEq()+"kW·h 累计"+monthDatas1.get((int)e.getX()-1).getEq()+"kW·h");
            tvContent2.setText(dateInfo2.getMonth()+"月：当日"+monthBarDatas2.get((int)e.getX()-1).getEq()+"kW·h 累计"+monthDatas2.get((int)e.getX()-1).getEq()+"kW·h");
        }
        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -mContext.getResources().getDimension(R.dimen.dp_400));
    }
}
